import {Linking} from "react-native";
import {Toast} from 'teaset';

export default {
    getParamsString:getParamsString,
    openTel:openTel,
}

function getParamsString(params){
    const dic = Object.keys(params).sort();
    let str = '';
    for(const key in dic){
        str += '&' + dic[key] + '=' + params[dic[key]];
    }
    return str.substr(1);
}

function openTel(tel){
    let url = 'tel: ' + tel;
    Linking.canOpenURL(url).then(supported => {
        if (!supported) {
          return  Toast.message("此设备不能拨打电话！！！！！");
        } else {
            return Linking.openURL(url);
        }
    }).catch(
        err =>  Toast.message("系统错误！")
    );
}
